package problem376;

//376.摆动序列
//https://leetcode.cn/problems/wiggle-subsequence/

class Solution {
    public int wiggleMaxLength(int[] nums) {
        int n = nums.length;
        if(n == 1) return 1;
        int count = 0, left = 0;
        for(int i = 0; i<n-1; i++) {
            int right = nums[i+1] - nums[i];
            if(right == 0) continue;
            if(left * right <= 0) count++;
            left = right;
        } 
        return count+1;
    }
}